package com.university.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.university.infrastructure.Result;
import com.university.pojo.cqe.command.*;
import com.university.pojo.cqe.query.MovieQuery;
import com.university.pojo.dto.MovieAdminDTO;
import com.university.pojo.dto.MovieTimeSlotAdminDTO;
import com.university.pojo.dto.MovieTimeSlotUserDTO;
import com.university.pojo.dto.MovieUserDTO;
import com.university.pojo.entity.Movie;
import com.university.pojo.entity.MovieTimeSlot;
import com.university.service.MovieService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Date: 2021/5/8 0:10
 * @Description:
 */
@Api(tags = {"电影接口"})
@RestController
public class MovieController extends BaseController {

    @Resource
    private MovieService movieService;

    @ApiOperationSupport(order = 1)
    @ApiOperation("管理员添加电影")
    @PostMapping("/admin/saveMovie")
    public Result saveMovie(@RequestBody CmdSaveMovie cmdSaveMovie) {
        movieService.saveMovie(cmdSaveMovie);
        return ok();
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation("管理员添加电影场次")
    @PostMapping("/admin/saveTimeSlot")
    public Result saveTimeSlot(@RequestBody CmdSaveTimeSlot cmdSaveTimeSlot) {
        movieService.saveTimeSlot(cmdSaveTimeSlot);
        return ok();
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation("管理员根据id修改电影")
    @PutMapping("/admin/updateMovie")
    public Result updateMovie(@RequestBody CmdUpdateMovie cmdUpdateMovie) {
        movieService.updateMovie(cmdUpdateMovie);
        return ok();
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation("管理员根据id修改电影场次")
    @PutMapping("/admin/updateTimeSlot")
    public Result updateTimeSlot(@RequestBody CmdUpdateTimeSlot cmdUpdateTimeSlot) {
        movieService.updateTimeSlot(cmdUpdateTimeSlot);
        return ok();
    }

    @ApiOperationSupport(order = 5)
    @ApiOperation("管理员根据id删除电影")
    @DeleteMapping("/admin/deleteMovie")
    public Result deleteMovie(Integer id) {
        movieService.deleteMovie(id);
        return ok();
    }

    @ApiOperationSupport(order = 6)
    @ApiOperation("管理员根据id删除电影场次")
    @DeleteMapping("/admin/deleteTimeSlot")
    public Result deleteTimeSlot(Integer id) {
        movieService.deleteTimeSlot(id);
        return ok();
    }

    @ApiOperationSupport(order = 7)
    @ApiOperation("管理员查询电影")
    @GetMapping("/admin/getMovie")
    public Result adminGetMovie(String type, String title,
                                @RequestParam(defaultValue = "1") Long page,
                                @RequestParam(defaultValue = "10") Long pageSize) {
        MovieQuery query = new MovieQuery();
        query.setType(type);
        query.setTitle(title);
        query.setPage(page);
        query.setPageSize(pageSize);
        IPage<Movie> moviePage = movieService.adminGetMovie(query);
        return ok(moviePage, MovieAdminDTO.class);
    }

    @ApiOperationSupport(order = 8)
    @ApiOperation("管理员查询电影场次")
    @GetMapping("/admin/getTimeSlot")
    public Result adminGetTimeSlot(Integer movieId) {
        List<MovieTimeSlot> list = movieService.adminGetTimeSlot(movieId);
        return ok(list, MovieTimeSlotAdminDTO.class);
    }

    @ApiOperationSupport(order = 9)
    @ApiOperation("用户查询所有电影")
    @GetMapping("/user/getMovie")
    public Result userGetMovie() {
        List<MovieUserDTO> movieList = movieService.userGetMovie();
        return ok(movieList);
    }

    @ApiOperationSupport(order = 10)
    @ApiOperation("用户查询所有电影场次")
    @GetMapping("/user/getTimeSlot")
    public Result userGetTimeSlot(Integer movieId) {
        List<MovieTimeSlotUserDTO> list = movieService.userGetTimeSlot(movieId);
        return ok(list);
    }
}
